/*
 *  Numerics.h
 *  NSE_SOLVER
 *
 *  Created by Patrick Zulian on 12/22/10.
 *  Copyright 2010 ICS - USI - Lugano. All rights reserved.
 *
 */


#ifndef NSE_SOLVER_NUMERICS_H
#define NSE_SOLVER_NUMERICS_H

#include <math.h>
#include <stdlib.h>
#include <algorithm>

#include "MathX.h"

namespace nsesolver {
	
	class Numerics
	{
		public:
		template< typename T >
		static T tolEps(const T x, const T y)
		{
			const T e = eps< T >();
			using std::max;
			const T maxAbs = max< T >( Math::abs< T >(x), Math::abs< T >(y) );
			
			return e * max< T >( Math::identity< T >(), maxAbs );
		}
		
		template< typename T >
		static T eps();
		
		
		template< typename T >
		static bool equalsEps(const T x, const T y)
		{
			return Math::abs< T >(x - y) <= Numerics::tolEps< T >(x, y);
		}
		

	};
	
}

#endif
